home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7087 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  86 lines

  1. Path: ix.netcom.com!netnews
  2. From: regmia@ix.netcom.com
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Help on assignment
  5. Date: Wed, 21 Feb 1996 06:47:43 GMT
  6. Organization: Netcom
  7. Message-ID: <4gef32$6g7@reader2.ix.netcom.com>
  8. References: <4gdmjm$1kr@cloner4.netcom.com>
  9. NNTP-Posting-Host: ix-lv3-20.ix.netcom.com
  10. X-NETCOM-Date: Tue Feb 20 10:45:54 PM PST 1996
  11. X-Newsreader: Forte Free Agent 1.0.82
  12.  
  13. dc30@ix.netcom.com(Diane Cogswell ) wrote:
  14.  
  15. >I'm hoping someone out there can help me out. I just started c++ and
  16. >I'm having problems with a couple assinments. Don't think I recieved
  17. >enough information.
  18. >The first one:
  19. >Write a function that normally takes one argument, the address of a
  20. >string, and prints that string once. However, if a second, type int
  21. >argument is provided and is greater than zero, the function prints the
  22. >string the number of times equal to the number of times indicated. 
  23.  
  24. >Second one is 
  25. >Write a function called zerosmaller that is passed to two int arguments
  26. >by reference and then sets the smaller of the two numbers to 0. Write a
  27. >main() program to exercise this function and print out the result.
  28. >I would really appreciate any help anyone can give me. I understood
  29. >Pascal but I'm having trouble trying to translate programs in c++. 
  30. >Thanks 
  31. > from discouraged
  32.  
  33.  
  34. Ok you declare your first function like so:
  35.  
  36. void printstring(char *thestring, int count = 0);
  37.  
  38. The 'count = 0' is a default, if no parameter is sent
  39. to it,  count defaults to 0 (Zero) or if a parameter is
  40. sent to it, count equals that value.
  41. ex.  printstring (MyName);   ---- count equals Zero
  42. ex  printstring (MyName, 5); --- count equals 5
  43.  
  44.  
  45. Ok you declare your second function like so:
  46.  
  47. void zerosmaller(int *firstnum, int *secondnum);
  48.  
  49. if actual code for this function would look like this:
  50.  
  51.  
  52. void zerosmaller (int* firstnum, int* secondnum)
  53. {
  54.   /* Check to see if they are even */
  55.    if (*firstnum == *secondnum)
  56.      return;
  57.  
  58.  /* Find which is smaller then change its value to Zero */
  59.    if (*firstnum < *secondnum)
  60.      *firstnum = 0;
  61.   else
  62.      *secondnum = 0;
  63. }
  64.  
  65.  
  66.  
  67. void main()
  68. {
  69.  #include <iostream.h>
  70.  
  71.    int a,b;
  72.  
  73.   a = 7;
  74.   b = 2;
  75. cout <<"Before zerosmaller:"<<a<<" "<<b<<'\n';
  76.  zerosmaller(&a, &b);
  77. cout <<"After zerosmaller:" <<a<<" "<<b<<'\n';
  78.  
  79.  
  80. }
  81.  
  82.  
  83. I Hope that works for you guy :)
  84.  
  85.  
  86.